﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Ekton_Manage_Framework.Methods.HttpSender
{
    public class HttpSenderHelper
    {
        private static int WaitingTime = 20000;//之前5000
        public async Task<string> FixUrl(string url)
        {
            if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                return "http://" + url;
            }
            return url;
        }

        public async Task<string> RunTask(Task<HttpResponseMessage> task)
        {
            bool flag;
            try
            {
                flag = task.Wait(WaitingTime);
            }
            catch (Exception innerException)
            {
                while (innerException.InnerException != null)
                {
                    innerException = innerException.InnerException;
                }
                throw innerException;
            }
            if (!flag)
            {
                throw new TimeoutException("Timeout");
            }
            return task.Result.Content.ReadAsStringAsync().Result;
        }
    }
}
